//
// Created by postgres on 4/20/17.
//
#include "../include/03StackQueue/queue.h"

Status SeqQueueInit(SeqQueue *sq) {
    sq->front = sq->rear = 0;
}

Status SeqQueueIsEmpty(SeqQueue *sq) {
    if (sq->front == 0 && sq->rear == 0)return TRUE;
    else return FALSE;
}

Status SeqQueueIsFull(SeqQueue *sq) {
    int rear=REAR(sq->rear);
    if (sq->front == rear){
        return TRUE;
    } else{
        return FALSE;
    }
}

Status EnSeqQueue(SeqQueue *sq, ElemType e) {
    if (SeqQueueIsFull(sq)) {
        printf("queue has full!\n");
        return ERROR;
    }

    sq->data[REAR(sq->rear)] = e;
    sq->rear = REAR(sq->rear);
    return OK;
}

Status DeSeqQueue(SeqQueue *sq, ElemType *e) {
    if (SeqQueueIsEmpty(sq)) {
        printf("queue empty!\n");
        return ERROR;
    }

    *e = sq->data[REAR(sq->front)];
    sq->front = FRONT(sq->front);
    return  OK;
}

void SeqQueue_test() {
    SeqQueue sq;
    SeqQueueInit(&sq);
    int e = 8190;
    EnSeqQueue(&sq, 8190);
    EnSeqQueue(&sq, 8191);
    EnSeqQueue(&sq, 8192);
    EnSeqQueue(&sq, 8193);
    EnSeqQueue(&sq, 8194);
    EnSeqQueue(&sq, 8195);
    EnSeqQueue(&sq, 8196);
    EnSeqQueue(&sq, 8197);
    EnSeqQueue(&sq, 8198);
    DeSeqQueue(&sq, &e);
    DeSeqQueue(&sq, &e);
    DeSeqQueue(&sq, &e);
    EnSeqQueue(&sq, 8199);
    EnSeqQueue(&sq, 8200);
    EnSeqQueue(&sq, 8201);
    EnSeqQueue(&sq, 8201);
}